package models

import (
	"time"

	"github.com/astaxie/beego/orm"
)

func init() {
	orm.RegisterModel(new(DataCountReviewDate))
}

type DataCountReviewDate struct {
	Id      int       `json:"-" orm:"column(id)"`
	Project string    `json:"project"`
	Date    time.Time `json:"date" orm:"type(date)"`
	Count   int       `json:"count"`
	Updated time.Time `json:"updated" orm:"type(datetime)"`
}

func (m *DataCountReviewDate) TableName() string {
	return "data_count_review_date"
}

func (m *DataCountReviewDate) GetById(id int) *DataCountReviewDate {
	query := orm.NewOrm().QueryTable(m.TableName())
	result := new(DataCountReviewDate)
	if err := query.One(result); err != nil {
		return nil
	}
	return result
}

func (m *DataCountReviewDate) GetByProject(project string) []DataCountReviewDate {
	query := orm.NewOrm().QueryTable(m.TableName())
	results := make([]DataCountReviewDate, 0)
	if _, err := query.Filter("project", project).All(&results); err != nil {
		return nil
	}
	return results
}

func (m *DataCountReviewDate) GetByDate(date time.Time) []DataCountReviewDate {
	query := orm.NewOrm().QueryTable(m.TableName())
	results := make([]DataCountReviewDate, 0)
	if _, err := query.Filter("date", date).All(&results); err != nil {
		return nil
	}
	return results
}
